home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15642 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c++,comp.lang.c
  4. Subject: Re: HELP: no mapping at the fault address
  5. Date: Sun, 07 Apr 96 19:17:55 GMT
  6. Organization: none
  7. Message-ID: <828904675snz@genesis.demon.co.uk>
  8. References: <opybocswab.fsf@sweetbay.will.uiuc.edu> <4k3qn8$1gk6@msunews.cl.msu.edu> <828829661snz@genesis.demon.co.uk> <828843649snz@tsys.demon.co.uk>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <828843649snz@tsys.demon.co.uk>
  15.            tomw@tsys.demon.co.uk "Tom Wheeley" writes:
  16.  
  17. >In article <828829661snz@genesis.demon.co.uk>
  18. >           fred@genesis.demon.co.uk "Lawrence Kirby" writes:
  19. >
  20. >> In article <4k3qn8$1gk6@msunews.cl.msu.edu>
  21. >>            jliu@perm.fw.msu.edu "Jianguo Liu" writes:
  22. >> 
  23. ...
  24. >> >The current line is 
  25. >> >
  26. >> >new_ptr=(strucut tree *) malloc(sizeof(struct tree));
  27. >> 
  28. >> Did you include stdlib.h? You must ensure that all functions that don't
  29. >> return int or are variadic are declared (it is best that all functions are
  30. >> declared). If that isn't the problem your program probably corrupted the
  31. >
  32. >Would I be right in saying that if he had omitted the cast for the return
  33. >value of malloc() then this error would have arisen as a warning in an
  34. >ISO compiler?  With (void *) being `equivalent' to any old pointer etc.
  35.  
  36. Without a declaration in scope the compiler must assume that malloc() returns
  37. int. Trying to convert implicitly from an int to a pointer (other than
  38. a constant expression with value 0) violates a constraint so, yes, the
  39. compiler must diagnose. void * isn't equilalent to other pointer types but
  40. may be converted implicitly to and from other pointer types (except pointers
  41. to functions) so the cast here can be omitted and probably should be since
  42. its main effect is to cover up a potential bug.
  43.  
  44. -- 
  45. -----------------------------------------
  46. Lawrence Kirby | fred@genesis.demon.co.uk
  47. Wilts, England | 70734.126@compuserve.com
  48. -----------------------------------------
  49.